package com.duan.util;

import org.springframework.util.DigestUtils;

public class MD5Util {
    //使用md5对字符串src加密
    public static String md5(String src){
        return DigestUtils.md5DigestAsHex(src.getBytes());
    }

    private static final String salt = "1a2b3c4d";

    //第一次加密
    public static String inputPassToFormPass(String inputPass){
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        System.out.println(str);
        return md5(str);
    }

    //第二次加密
    public static String formPassToDBPass(String formPass, String salt){
        String str = "" + salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }

    //从明文代码到数据库存储（经过了两次加密）
    public static String inputPassToDbPass(String inputPass, String saltDB){
        String formPass = inputPassToFormPass(inputPass);
        String dbPass = formPassToDBPass(formPass, saltDB);
        return dbPass;
    }

    public static void main(String[] args){
        System.out.println("15319781811");
        System.out.println(inputPassToDbPass("123456", "1a2b3c4d"));
    }


}
